var e = null,
  l = null,
  t = null,
  n = null,
  i = null,
  a = null,
  s = null,
  o = null,
  u = null,
  r = null,
  c = 0,
  f = 0,
  g = getApp(),
  h = null,
  h1 = 0;
var tms, tps, bjtps, xxjss, nums, xpzcss, zdys, csrs;
var jtggzt = 0;
var tjcs = new Array();

Page({
  data: {
    prurl: null,
    hidden: !0,
    hidden1: !1,
    ggxx: "您的测试报告正在生成，点击下方按钮即可查看测试结果。",
    csnr: null
  },
  onLoad: function (m) {
    jtggzt = 0;
    wx.showShareMenu();
    //跳转页面参数
    tms = m.tms, tps = m.tps, bjtps = m.bjtps, xxjss = m.xxjss, nums = m.nums, xpzcss = m.xpzcss, zdys = m.zdys, csrs = m.csrs;
    //参数
    h1 = 0;
    switch (c = 0, f = 0, e = m.csm, l = m.dfjs, t = m.bq1, n = m.bq2, i = m.bq3, a = m.bq4,
    s = m.bq5, o = m.df, u = m.ztpj, r = m.nickname, h = m.bjtp) {
      case "1":
        h = "/images/main1.jpg";
        break;
      case "2":
        h = "/images/main2.jpg";
        break;
      case "3":
        h = "/images/main3.jpg";
        break;
      case "4":
        h = "/images/main4.jpg";
        break;
      case "5":
        h = "/images/main5.jpg";
        break;
      default:
        h1 = 1;
    }
    var d = new Promise(function (e, l) {
      wx.getImageInfo({
        src: h,
        success: function (l) {
          c = 1, e(l);
        }
      });
    }),
      x = new Promise(function (e, l) {
        wx.getImageInfo({
          src: g.globalData.userInfo.avatarUrl,
          success: function (l) {
            f = 1, e(l);
          },
          fail: function () {
            wx.showToast({
              title: "连接服务器失败，请重新载入该页面！",
              icon: "none",
              duration: 2e3
            });
          }
        })
      }),
      xcxm = new Promise(function (e, l) {
        wx.getImageInfo({
          src: "/images/xcxm.png",
          success: function (l) {
            f = 1, e(l);
          }
        });
      });
    Promise.all([d, x, xcxm]).then(function (c) {
      var f = wx.createCanvasContext("shareImg");
      if (h1 == 1) {
        f.drawImage(c[0].path, 0, 0, 320, 630)
      } else {
        f.drawImage("../../" + c[0].path, 0, 0, 320, 630)
      }
      if (o != 'zdy' && o != 'zdx' && o != 'zdt') {
        f.drawImage(c[1].path, 30, 140, 50, 50), f.drawImage("../../" + c[2].path, 130, 555, 60, 60),
          f.setFillStyle("black"), f.setTextAlign("left"), f.setFontSize(18), f.fillText("名字:" + r, 88, 155)
        if (f.setTextAlign("left"), f.setFillStyle("red"), f.setFontSize(18), "null" != t) {
          f.setFillStyle("black"), f.fillText(t, 80, 220), f.setFillStyle("red"), f.fillText("标签：", 30, 220), f.fillText("综合评价", 30, 350), f.fillText("测试", 195, 590), f.fillText("码上", 90, 590);
          f.setFillStyle("black");
          for (var g = 0, h = 375; g < u.length; g += 14, h += 25) f.fillText(u.substring(g, g + 14), 30, h);
        }
        if ("null" != n && f.fillText(n, 80, 245), "null" != i && f.fillText(i, 80, 270),
          "null" != a && f.fillText(a, 80, 295), "null" != s && f.fillText(s, 80, 320),
          "null" == t && "null" == n && "null" == i && "null" == a && "null" == s) {
          f.fillText("综合评价", 30, 220), f.fillText("测试", 195, 590), f.fillText("码上", 90, 590), f.setFontSize(18), f.setFillStyle("black");
          for (var g = 0, h = 245; g < u.length; g += 14, h += 25) f.fillText(u.substring(g, g + 14), 30, h)
        }
        f.setFillStyle("black"), f.setTextAlign("left"), f.setFontSize(18), f.fillText(l + o, 88, 185), f.setFontSize(25), f.setFillStyle("red"), f.setTextAlign("center"), f.fillText(e, 160, 115)
      } else if (o == 'zdy') {
        f.drawImage("../../" + c[2].path, 5, 560, 65, 65), f.drawImage(c[1].path, 75, 562, 60, 60),
          f.setFillStyle("black"), f.setTextAlign("left"), f.setFontSize(19), f.fillText(r, 138, 586), f.fillText("长按图片识别小程序", 138, 617)
      } //自定义模板
      else if (o == 'zdx') {
      } //空模板
      else if (o == 'zds') {
        f.setFontSize(19);
        f.setFillStyle(s);
        f.fillText(r, i, a);
        f.drawImage(c[1].path, t, n, 60, 60);
        //t:头像X坐标 n:头像Y坐标 i:昵称X坐标 a:昵称Y坐标 s:昵称颜色
      }//头像昵称自定义模板
      else if (o == 'zdt') {
        f.setFontSize(19)
        f.setFillStyle("black")
        for (var g = 0, h = 70; g < u.length; g += 16, h += 25) f.fillText(u.substring(g, g + 16), 9.5, h)
        f.setFontSize(25), f.setFillStyle("red"), f.setTextAlign("center"), f.fillText(e, 160, 35)
        f.drawImage("../../" + c[2].path, 5, 560, 65, 65), f.drawImage(c[1].path, 75, 562, 60, 60),
          f.setFillStyle("black"), f.setTextAlign("left"), f.setFontSize(19), f.fillText(r, 138, 586), f.fillText("长按图片识别小程序", 138, 617)
      } //书信模板
      f.stroke(), f.draw();
    })
  },
  onReady: function () {
    var o = this;
    if (g.globalData.csnr == null) {
      wx.request({
        url: g.globalData.url + "ndzscs/request1/main.php",
        method: "GET",
        header: {
          "content-type": "application/json"
        },
        success: function (c) {
          for (var i = 0; i < 15; i++) {
            tjcs[i] = c.data[i];
          }
          o.setData({
            csnr: tjcs
          })
        }
      })//获取推荐测试
    } else {
      for (var i = 0; i < 15; i++) {
        tjcs[i] = g.globalData.csnr[i];
      }
      o.setData({
        csnr: tjcs
      })
    }//提前加载成功
  },
  onPullDownRefresh: function () { },
  onShareAppMessage: function () { //分享代码
    return {
      title: "我完成了“" + tms + "”你也来评测一下吧！",
      path: "/pages/main/main?tm=" + tms + "&tp=" + tps + "&bjtp=" + bjtps + "&xxjs=" + xxjss + "&num=" + nums + "&xpzcs=" + xpzcss + "&zdy=" + zdys + "&csrs=" + csrs,
      imageUrl: this.data.prurl
    };
  },
  share: function () {
    jtggzt = 0;
    var e = this;
    if (e.data.hidden1 == !1) {
      wx.showLoading({
        title: "获取报告中"
      })
      wx.canvasToTempFilePath({
        x: 0,
        y: 0,
        width: 320,
        height: 630,
        destWidth: 960,
        destHeight: 1890,
        canvasId: "shareImg",
        success: function (l) {
          e.setData({
            hidden: !1,
            hidden1: !0,
            prurl: l.tempFilePath
          });
          wx.hideLoading();
        }
      })
    }
  },
  save: function () {
    var e = this;
    wx.saveImageToPhotosAlbum({
      filePath: e.data.prurl,
      success: function (e) {
        wx.showModal({
          content: "图片已保存到相册，赶紧晒一下吧",
          showCancel: !1,
          confirmText: "好的",
          confirmColor: "#333"
        });
      },
      fail: function () {
        wx.showToast({
          title: "保存图片失败！",
          icon: "none",
          duration: 3e3
        });
      }
    });
  },
  kscss: function (t) {
    var o = t.currentTarget.dataset.index;
    wx.redirectTo({
      url: "/pages/ceshi/ceshi?tm=" + this.data.csnr[o][1] + "&tp=" + this.data.csnr[o][4] + "&bjtp=" + this.data.csnr[o][5] + "&xxjs=" + this.data.csnr[o][3] + "&num=" + this.data.csnr[o][0] + "&xpzcs=0" + "&zdy=" + this.data.csnr[o][10] + "&csrs=" + this.data.csnr[o][6],
    });
  },
});